<?php
/**
 *
 *
 * This file is part of Webappkit, a packages system for PHP web apps
 * @link http://webappkit.net
 * @package
 * @subpackage
 * @author J.Ducastel <nospam0@ducastel.name>
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */

/**
 * @property string $regex validation regex
 */
class DjRegexField extends DjField {

    /**
     * return the cleaned value
     * if value does not validate, raise a DjValidationError
     * @param mixed $input
     * @return mixed
     */
    public function clean($input) {
        $input = $this->_normalize($input);
        $this->_cleanRequired($input);
        if (!preg_match($this->regex, $input)) {
            throw new DjValidationError($this->error_messages['invalid']);
        }
        return $input;
    }

    protected $regex;
}